{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import os\n",
    "import glob"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def get_list_of_files():\n",
    "    \n",
    "    files = glob.glob(os.path.join('/data/Public Data/IEEE Data Fusion Contest 2019/DFC2019_track4_trainval/Train-Track4/',\"*_PC3.txt\"))\n",
    "    return sorted(files)\n",
    "\n",
    "files=get_list_of_files()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "110\n"
     ]
    }
   ],
   "source": [
    "print(len(files))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/data/Public Data/IEEE Data Fusion Contest 2019/DFC2019_track4_trainval/Train-Track4/JAX_004_PC3.txt'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "files[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/data/Public Data/IEEE Data Fusion Contest 2019/DFC2019_track4_trainval/Train-Track4/JAX_004_\n"
     ]
    }
   ],
   "source": [
    "print(files[0][:-7])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('/data/Public Data/IEEE Data Fusion Contest 2019/DFC2019_track4_trainval/Train-Track4',\n",
       " 'JAX_004_PC3.txt')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.path.split(files[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(481290, 5) (481290, 1)\n",
      "finishd numbers:0 (777643, 5) (777643, 1)\n"
     ]
    }
   ],
   "source": [
    "for i in range(1):\n",
    "    origintxtdata=np.array(pd.read_csv(files[i],sep=',',header=None))\n",
    "    labelfile=files[i][:-7]+'CLS.txt'\n",
    "    origintxtlabel=np.array(pd.read_csv(labelfile,header=None))\n",
    "    print(origintxtdata.shape,origintxtlabel.shape)\n",
    "    \n",
    "    tree=origintxtdata[origintxtlabel[:,0]==5,:]\n",
    "    treelabel=origintxtlabel[origintxtlabel[:,0]==5,:]\n",
    "    tree_new=np.tile(tree,[1,1])+np.around(np.random.uniform(-0.3,0.3,(tree.shape[0],5)),decimals=8)\n",
    "    treelabel_new=np.tile(treelabel,[1,1])\n",
    "    \n",
    "    building=origintxtdata[origintxtlabel[:,0]==6,:]\n",
    "    buildinglabel=origintxtlabel[origintxtlabel[:,0]==6,:]\n",
    "    building_new=np.tile(building,[2,1])+np.around(np.random.uniform(-0.3,0.3,(2*building.shape[0],5)),decimals=8) \n",
    "    buildinglabel_new=np.tile(buildinglabel,[2,1])\n",
    "    \n",
    "    water=origintxtdata[origintxtlabel[:,0]==9,:]\n",
    "    waterlabel=origintxtlabel[origintxtlabel[:,0]==9,:]\n",
    "    water_new=np.tile(water,[50,1])+np.around(np.random.uniform(-0.3,0.3,(50*water.shape[0],5)),decimals=8)\n",
    "    waterlabel_new=np.tile(waterlabel,[50,1])\n",
    "    \n",
    "    road=origintxtdata[origintxtlabel[:,0]==17,:]\n",
    "    roadlabel=origintxtlabel[origintxtlabel[:,0]==17,:]\n",
    "    road_new=np.tile(road,[100,1])+np.around(np.random.uniform(-0.3,0.3,(100*road.shape[0],5)),decimals=8)\n",
    "    roadlabel_new=np.tile(roadlabel,[100,1])\n",
    "    \n",
    "#     print(tree_new.shape,treelabel_new.shape)\n",
    "#     print(building_new.shape,buildinglabel_new.shape)\n",
    "#     print(water_new.shape,waterlabel_new.shape)\n",
    "#     print(road_new.shape,roadlabel_new.shape)\n",
    "    \n",
    "    newdata=np.concatenate([origintxtdata,tree_new,building_new,water_new,road_new],axis=0)\n",
    "    newlabel=np.concatenate([origintxtlabel,treelabel_new,buildinglabel_new,waterlabel_new,roadlabel_new],axis=0)\n",
    "    \n",
    "    print('finishd numbers:{}'.format(i),newdata.shape,newlabel.shape)\n",
    "    \n",
    "    ###Output\n",
    "    path,datafilename=os.path.split(files[i])\n",
    "    outputdatapath='/data/DW/DataFusion/dfc2019-master/track4/trn_data_folder/postprocesstext/'+datafilename\n",
    "    \n",
    "    dt_data=pd.DataFrame(newdata)\n",
    "    dt_data.to_csv(outputdatapath,sep=',',header=None,index=False)\n",
    "    \n",
    "    path,labelfilename=os.path.split(labelfile)\n",
    "    outputlabelpath='/data/DW/DataFusion/dfc2019-master/track4/trn_data_folder/postprocesstext/'+labelfilename\n",
    "    \n",
    "    dt_label=pd.DataFrame(newlabel)\n",
    "    dt_label.to_csv(outputlabelpath,sep=',',header=None,index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (py4torch_tf)",
   "language": "python",
   "name": "pytorch"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
